package org.devgframwork.datasync.admin.support.init.impl;


import org.devgframwork.datasync.admin.support.init.AbstractInit;
import org.devgframwork.datasync.core.entity.ElasticSearchConfig;
import org.devgframwork.datasync.core.support.DataSourceMemory;
import org.devgframwork.datasync.core.utils.CommonUtil;
import org.devgframwork.datasync.es56.entity.ElasticSearchConfigPO;
import org.devgframwork.datasync.es56.executors.Es56Executor;
import lombok.extern.slf4j.Slf4j;
import org.devgframwork.datasync.admin.rabbit.service.EsConfigService;
import org.springframework.beans.BeanUtils;

import java.util.List;

@Slf4j
public class Es56Init extends AbstractInit {

    public Es56Init(AbstractInit nextAbstractInit) {
        super(nextAbstractInit);
    }

    @Override
    public void initComponent() {
        EsConfigService esConfigService = DataSourceMemory.applicationContext.getBean(EsConfigService.class);
        List<ElasticSearchConfig> es56ConfigList = esConfigService.getEs56ConfigList();
        if (CommonUtil.isEmpty(es56ConfigList)) {
            log.warn("es56ConfigList is empty");
            return;
        }
        for (ElasticSearchConfig elasticSearchConfig : es56ConfigList) {
            ElasticSearchConfigPO elasticSearchConfigPO = new ElasticSearchConfigPO();
            BeanUtils.copyProperties(elasticSearchConfig, elasticSearchConfigPO);
            Es56Executor.initEsConfig(elasticSearchConfigPO);
        }
        log.info("init EsSearch jestClient finish ... ");
    }
}
